package com.lxy.file.server.impl;

import java.util.concurrent.*;

/**
 * @Author lxy
 * @Date 2021/12/29 13:42
 * @Description
 */
public class FileMergeHandlerExecutePool {
    private ThreadPoolExecutor executor;

    public FileMergeHandlerExecutePool(int pathFilesSize) {
        int corePoolSize = Runtime.getRuntime().availableProcessors()*2;
        int maxPoolSize = corePoolSize+pathFilesSize;
        executor = new ThreadPoolExecutor(corePoolSize,
                maxPoolSize,1000, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(pathFilesSize*2));
    }

    public void execute(Runnable task){
        executor.execute(task);
    }

    public Future<Boolean> submit(Callable<Boolean> task){
        Future<Boolean> submit = executor.submit(task);
        return submit;
    }
}
